package com.example.aircraftwar.codes.application;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;

import com.example.aircraftwar.R;
import com.example.aircraftwar.codes.aircraft.BossEnemy;
import com.example.aircraftwar.codes.aircraft.EliteEnemy;
import com.example.aircraftwar.codes.aircraft.HeroAircraft;
import com.example.aircraftwar.codes.aircraft.HeroAircraft2;
import com.example.aircraftwar.codes.aircraft.MobEnemy;
import com.example.aircraftwar.codes.basic.GameBackground;
import com.example.aircraftwar.codes.bullet.BossBullet;
import com.example.aircraftwar.codes.bullet.EnemyBullet;
import com.example.aircraftwar.codes.bullet.HeroBullet;
import com.example.aircraftwar.codes.prop.BloodProp;
import com.example.aircraftwar.codes.prop.BombProp;
import com.example.aircraftwar.codes.prop.BulletProp;

import java.util.HashMap;
import java.util.Map;

public class ImageManager {

    /**
     * 类名-图片 映射，存储各基类的图片 <br>
     * 可使用 CLASSNAME_IMAGE_MAP.get( obj.getClass().getName() ) 获得 obj 所属基类对应的图片
     */
    private static final Map<String, Bitmap> CLASSNAME_IMAGE_MAP = new HashMap<>();

    public static Bitmap BACKGROUND_IMAGE_SIMPLE;
    public static Bitmap BACKGROUND_IMAGE_NORMAL;
    public static Bitmap BACKGROUND_IMAGE_DIFFICULT;
    public static Bitmap HERO_IMAGE;
    public static Bitmap HERO2_IMAGE;
    public static Bitmap MOB_ENEMY_IMAGE;
    public static Bitmap ELITE_ENEMY_IMAGE;
    public static Bitmap BOSS_ENEMY_IMAGE;
    public static Bitmap HERO_BULLET_IMAGE;
    public static Bitmap ENEMY_BULLET_IMAGE;
    public static Bitmap BLOOD_PROP_IMAGE;
    public static Bitmap BOMB_PROP_IMAGE;
    public static Bitmap BULLET_PROP_IMAGE;
    public static Bitmap BOSS_BULLET_IMAGE;

    public static void initImages(Context context) {
        BACKGROUND_IMAGE_SIMPLE = BitmapFactory.decodeResource(context.getResources(), R.mipmap.bg);
        BACKGROUND_IMAGE_NORMAL = BitmapFactory.decodeResource(context.getResources(), R.mipmap.bg3);
        BACKGROUND_IMAGE_DIFFICULT = BitmapFactory.decodeResource(context.getResources(), R.mipmap.bg4);

        Matrix matrix = new Matrix();
        matrix.postScale(2,2);

        HERO_IMAGE = BitmapFactory.decodeResource(context.getResources(), R.mipmap.hero);
        HERO_IMAGE = Bitmap.createBitmap(HERO_IMAGE,0,0,HERO_IMAGE.getWidth(),HERO_IMAGE.getHeight(),matrix,false);
        MOB_ENEMY_IMAGE = BitmapFactory.decodeResource(context.getResources(), R.mipmap.mob);
        MOB_ENEMY_IMAGE = Bitmap.createBitmap(MOB_ENEMY_IMAGE,0,0,MOB_ENEMY_IMAGE.getWidth(),MOB_ENEMY_IMAGE.getHeight(),matrix,false);
        ELITE_ENEMY_IMAGE = BitmapFactory.decodeResource(context.getResources(), R.mipmap.elite);
        ELITE_ENEMY_IMAGE = Bitmap.createBitmap(ELITE_ENEMY_IMAGE,0,0,ELITE_ENEMY_IMAGE.getWidth(),ELITE_ENEMY_IMAGE.getHeight(),matrix,false);
        BOSS_ENEMY_IMAGE = BitmapFactory.decodeResource(context.getResources(), R.mipmap.boss);
        BOSS_ENEMY_IMAGE = Bitmap.createBitmap(BOSS_ENEMY_IMAGE,0,0,BOSS_ENEMY_IMAGE.getWidth(),BOSS_ENEMY_IMAGE.getHeight(),matrix,false);
        HERO_BULLET_IMAGE = BitmapFactory.decodeResource(context.getResources(), R.mipmap.bullet_hero);
        HERO_BULLET_IMAGE = Bitmap.createBitmap(HERO_BULLET_IMAGE,0,0,HERO_BULLET_IMAGE.getWidth(),HERO_BULLET_IMAGE.getHeight(),matrix,false);
        ENEMY_BULLET_IMAGE = BitmapFactory.decodeResource(context.getResources(), R.mipmap.bullet_enemy);
        ENEMY_BULLET_IMAGE = Bitmap.createBitmap(ENEMY_BULLET_IMAGE,0,0,ENEMY_BULLET_IMAGE.getWidth(),ENEMY_BULLET_IMAGE.getHeight(),matrix,false);
        BLOOD_PROP_IMAGE = BitmapFactory.decodeResource(context.getResources(), R.mipmap.prop_blood);
        BLOOD_PROP_IMAGE = Bitmap.createBitmap(BLOOD_PROP_IMAGE,0,0,BLOOD_PROP_IMAGE.getWidth(),BLOOD_PROP_IMAGE.getHeight(),matrix,false);
        BOMB_PROP_IMAGE = BitmapFactory.decodeResource(context.getResources(), R.mipmap.prop_bomb);
        BOMB_PROP_IMAGE = Bitmap.createBitmap(BOMB_PROP_IMAGE,0,0,BOMB_PROP_IMAGE.getWidth(),BOMB_PROP_IMAGE.getHeight(),matrix,false);
        BULLET_PROP_IMAGE = BitmapFactory.decodeResource(context.getResources(), R.mipmap.prop_bullet);
        BULLET_PROP_IMAGE = Bitmap.createBitmap(BULLET_PROP_IMAGE,0,0,BULLET_PROP_IMAGE.getWidth(),BULLET_PROP_IMAGE.getHeight(),matrix,false);
        BOSS_BULLET_IMAGE = BitmapFactory.decodeResource(context.getResources(), R.mipmap.boss_bullet);
        BOSS_BULLET_IMAGE = Bitmap.createBitmap(BOSS_BULLET_IMAGE,0,0,BOSS_BULLET_IMAGE.getWidth(),BOSS_BULLET_IMAGE.getHeight(),matrix,false);
        HERO2_IMAGE = BitmapFactory.decodeResource(context.getResources(), R.mipmap.hero2);
        HERO2_IMAGE = Bitmap.createBitmap(HERO2_IMAGE,0,0,HERO2_IMAGE.getWidth(),HERO2_IMAGE.getHeight(),matrix,false);


        CLASSNAME_IMAGE_MAP.put(HeroAircraft.class.getName(), HERO_IMAGE);
        CLASSNAME_IMAGE_MAP.put(MobEnemy.class.getName(), MOB_ENEMY_IMAGE);
        CLASSNAME_IMAGE_MAP.put(HeroBullet.class.getName(), HERO_BULLET_IMAGE);
        CLASSNAME_IMAGE_MAP.put(EnemyBullet.class.getName(), ENEMY_BULLET_IMAGE);
        CLASSNAME_IMAGE_MAP.put(EliteEnemy.class.getName(), ELITE_ENEMY_IMAGE);
        CLASSNAME_IMAGE_MAP.put(BossEnemy.class.getName(), BOSS_ENEMY_IMAGE);
        CLASSNAME_IMAGE_MAP.put(BloodProp.class.getName(), BLOOD_PROP_IMAGE);
        CLASSNAME_IMAGE_MAP.put(BombProp.class.getName(), BOMB_PROP_IMAGE);
        CLASSNAME_IMAGE_MAP.put(BulletProp.class.getName(), BULLET_PROP_IMAGE);
        CLASSNAME_IMAGE_MAP.put(BossBullet.class.getName(), BOSS_BULLET_IMAGE);
        CLASSNAME_IMAGE_MAP.put(HeroAircraft2.class.getName(), HERO2_IMAGE);
    }

    public static Bitmap get(String className){
        return CLASSNAME_IMAGE_MAP.get(className);
    }

    public static Bitmap get(Object obj){
        if (obj == null){
            return null;
        }
        return get(obj.getClass().getName());
    }

}